﻿using System;
using System.Collections.Generic;
using System.Text;
using Maticsoft.DBUtility;
using System.Data;

namespace ExtendBLL
{
    public class Standard
    {
        /// <summary>
        /// 获取自评信息
        /// </summary>
        /// <param name="ID">主题ID</param>
        /// <returns></returns>
        public DataSet GetSelfInfoByTitleID(int ID,string LabID,int Time)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.*,b.* from Standard a  left join Evaluation b on a.[ID]=b.StandarID where a.EvTitleID=" + ID + " and b.LabID=" + LabID + " and b.EvTime=" + Time);

            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 添加实验室自评信息
        /// </summary>
        /// <param name="LabID"></param>
        /// <param name="list"></param>
        public void AddSelfInfo(int LabID, List<string[]> list,int Time)
        {
            StringBuilder strSql = new StringBuilder();

            for (int i = 0; i < list.Count; i++)
            {
                strSql.Append(" insert Evaluation(Comment,Result,Remark,LabID,[Date],StandarID,EvTime) values('" + list[i][0].ToString() + "'," + int.Parse(list[i][2].ToString()) + ",'" + list[i][1].ToString() + "','" + LabID.ToString() + "','" + DateTime.Now + "'," + int.Parse(list[i][3].ToString()) + "," + Time + ") ");
            }
            DbHelperSQL.ExecuteReader(strSql.ToString());
        }

        /// <summary>
        /// 更新实验室自评信息
        /// </summary>
        /// <param name="LabID"></param>
        /// <param name="list"></param>
        public void UpdateSelfInfo(int LabID, List<string[]> list)
        {
            StringBuilder strSql = new StringBuilder();

            for (int i = 0; i < list.Count; i++)
            {
                strSql.Append(" update Evaluation set Comment='" + list[i][0].ToString() + "',Result=" + int.Parse(list[i][2].ToString()) + ",Remark='" + list[i][1].ToString() + "',[Date]='" + DateTime.Now + "' where EID=" + int.Parse(list[i][3].ToString()));
            }
            DbHelperSQL.ExecuteReader(strSql.ToString());
        }

        /// <summary>
        /// 获取日期列表
        /// </summary>
        /// <param name="TitleID"></param>
        /// <param name="LabID"></param>
        /// <returns></returns>
        public DataSet GetDateList(int TitleID, int LabID)
        {
            string sql = "select distinct b.EvTime,b.[Date] from Standard a  left join Evaluation b on a.[ID]=b.StandarID where a.EvTitleID=" + TitleID + " and b.LabID=" + LabID;

            return DbHelperSQL.Query(sql);
        }

        public DataSet GetMaxTime(int TitleID, int LabID)
        {
            string sql = "select max(b.EvTime) from Standard a  left join Evaluation b on a.[ID]=b.StandarID where a.EvTitleID=" + TitleID + " and b.LabID=" + LabID;

            return DbHelperSQL.Query(sql);
        }

        public void DeleteEva(string strwhere)
        {
            string sql = "delete from Evaluation where " + strwhere;

            DbHelperSQL.ExecuteReader(sql);
        }
    }
}
